<template>
  <div>
    <headers></headers>
    <div id="goodsDetail">
      <div class="crumbs">
        <div class="crumbs-content">
          <span @click="goHome()">首页
            <i></i>
          </span>
          <span>{{productView.name}}</span>
        </div>
      </div>
      <div id="goods-content"  v-if="picList.length>0">
        <div class="goods">
          <div class="goods-img">
            <div class="main-img">
              <div class="big-box">
                <img :src="picList[0].picUrl" >
              </div>
              <div class="box">
                <div class="list">
                  <ul>
                    <li v-for="item in picList" :key="item.id"><img :src="item.picUrl"></li>
                  </ul>
                </div>
              </div>
            </div>
          </div>
          <div class="goods-info">
            <div class="good-name">{{ productView.name }}</div>
            <div class="good-price">
              <div class="price">
                <label>价格</label>
                <span>￥<b>{{ productView.price }}</b></span>
              </div>
            </div>
            <div class="description"><p v-for="(item,index) in description" :key="index">● {{item}}</p></div>
            <div class="address">
              <label>配送至</label>
                <div></div>
                有货
            </div>
            <div class="selection" v-if="catSpecList.length>0">
              <p style="margin-bottom: 10px" class="color">
                <label>选择颜色</label>
                <span v-for="(item) in specPicList" :key="item.specValueId">
                  <img :src="item.picUrl">
                </span>
              </p>
              <p class="capacity"  v-if="catSpecList.length>0 && catSpecList[1]">
                <label>选择容量</label>
                <span v-for="item in catSpecList[1].specValueList" :key="item.valueId">{{ item.value }}</span>
              </p>
              <div class="num">
                <label>数量</label>
                <div>
                  <div class="number">
                    <div>
                      <input type="text" value="1">
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="buy-btn">
              <div class="buy">立即购买</div>
              <div class="add-cart">加入购物车</div>
              <div class="kefu">在线客服</div>
            </div>
          </div>
        </div>
        <div class="introduction">
          <div class="recommend"></div>
          <div class="detail">
            <div class="title">
              <p v-for="(item,index) in introductionList" :key="index">{{item}}</p>
            </div>
            <div class="content">
              <div class="introduction-img" v-html="goodsView.details"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <footers></footers>
  </div>
</template>

<script>
import { goodsSpec,goodsDetail } from "@/api/index"
import Headers from '@/components/header.vue'
import Footers from '@/components/footer.vue'
export default {
  async created() {
    let data = this.$route.query.id;
    const {result: { specPicList,productView, shoppingGuideList, userShippingAddressView, goodsView,catSpecList }} = await goodsDetail({goodsId:data,cityId:424});
    this.productView = productView;
    this.shoppingGuideList = shoppingGuideList;
    this.userShippingAddressView = userShippingAddressView;
    this.goodsView = goodsView;
    this.catSpecList = catSpecList;
    const {result:  { picList }} = await goodsSpec({goodsId:data,cityId:324})
    this.picList = picList;
    
    let arr = goodsView.description.split("●");
    arr.shift()
    this.description = arr;
    this.specPicList = _.uniqWith(specPicList.reverse(), _.isEqual);
    
  },
  components: { Headers, Footers },
  data() {
    return {
      specPicList: [],
      productView: {},
      shoppingGuideList: {},
      userShippingAddressView: {},
      goodsView: {},
      catSpecList: [],
      picList: [],
      description: [],
      introductionList: ["商品介绍","规格参数","商品评价","精彩问答","售后服务","了解顺电"]
    }
  },
  methods: {
    goHome() {
      this.$router.push("/home")
    }
  }

}
</script>

<style>
  #goodsDetail {
    background: white;
    color: #666;
  }
  p {
    margin: 0;
  }
  #goodsDetail > .crumbs {
    background: #f7f7f7;
    height: 40px;
    line-height: 40px;
    vertical-align: middle;
  }
  #goodsDetail > .crumbs > .crumbs-content {
    line-height: 40px;
    width: 1200px;
    margin: 0 auto;
  }
  #goodsDetail > .crumbs > .crumbs-content > span{
    float: left;
    font-size: 12px;
  }
  #goodsDetail > .crumbs > .crumbs-content > span:first-of-type {
    cursor: pointer;
  }
  #goodsDetail > .crumbs > .crumbs-content  i::before {
    content: ">";
    color: #c0c4cc;
    margin: 0 6px;
    font-size: 14px;
  }
  #goodsDetail > .crumbs > .crumbs-content > span:last-of-type {
    max-width: 1000px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    float: left;
  }
  #goods-content {
    margin: 10px auto;
    width: 1200px;
  }
  #goods-content > .goods {
    display: flex;
  }
  #goods-content > .goods > .goods-img {
    width: 450px;
  }
  #goods-content > .goods > .goods-img > .main-img {
    width: 450px;
    position: relative;
  }
  #goods-content > .goods > .goods-img > .main-img > .big-box {
    border: 1px solid #eee;
    height: 450px;
    margin-bottom: 20px;
  }
  #goods-content > .goods > .goods-img > .main-img > .big-box > img {
    width: 100%;
    height: 100%;
    display: block;
  }
  #goods-content > .goods > .goods-img > .main-img > .box {
    height: 62px;
    position: relative;
    width: 100%;
  }
  #goods-content > .goods > .goods-img > .main-img > .box > .list {
    height: 58px;
    margin: 0 auto;
    overflow: hidden;
    width: 390px;
    position: relative;
  }
  #goods-content > .goods > .goods-img > .main-img > .box > .list > ul {
    position: absolute;
    width: 5000px;
  }
  #goods-content > .goods > .goods-img > .main-img > .box > .list  li {
    float: left;
    margin: 0 11.9px;
  }
  #goods-content > .goods > .goods-img > .main-img > .box > .list  img {
    border: 2px solid #fff;
    height: 50px;
    width: 50px;
  }

  #goods-content > .goods > .goods-info {
    width: 700px;
    margin-left: 50px;
  }

  #goods-content > .goods > .goods-info > .good-name {
    color: #333;
    font-size: 20px;
    font-weight: 400;
    margin-bottom: 5px;
    text-align: start;
  }
  #goods-content > .goods > .goods-info > .good-price {
    background: #f3f3f3;
    padding-bottom: 10px;
  }
  #goods-content > .goods > .goods-info > .good-price > .price {
    align-items: flex-end;
    color: #ea1616;
    display: flex;
    font-size: 16px;
    margin-left: 10px;
    padding-top: 10px;
  }
  #goods-content > .goods > .goods-info > .good-price > .price > label {
    color: #666;
    font-size: 12px;
    margin-bottom: 3px;
    text-align: justify;
    text-align-last: justify;
    width: 50px !important;
  }
  #goods-content > .goods > .goods-info > .good-price > .price > span {
    color: #ea1616;
    font-size: 16px;
    margin-left: 25px;
  }
  #goods-content > .goods > .goods-info > .good-price > .price b {
    color: #ea1616;
    font-size: 24px;
  }
  #goods-content > .goods > .goods-info > .description {
    border-top: 1px solid #dbdbdb;
    padding: 10px;
  }
  #goods-content > .goods > .goods-info > .description > p {
    line-height: 1.8;
    text-align: start;
    margin: 0;
  }
  #goods-content > .goods > .goods-info > .address {
    align-items: center;
    color: #666;
    display: flex;
    margin-top: 14px;
    margin-bottom: 10px;
  }
  #goods-content > .goods > .goods-info > .address > label {
    margin-left: 10px;
    font-size: 12px;
    margin-bottom: 3px;
    text-align: justify;
    text-align-last: justify;
    width: 50px !important;
  }
  #goods-content > .goods > .goods-info > .selection {
    border-top: 1px solid #dbdbdb;
  }
  #goods-content > .goods > .goods-info > .selection > p {
    margin: 20px 10px;
    text-align: start;
  }
  #goods-content > .goods > .goods-info > .selection > p > label {
    margin-right: 25px;
    text-align: justify !important;
    font-size: 12px;
    margin-bottom: 3px;
    text-align-last: justify;
  }
  #goods-content > .goods > .goods-info > .selection > .color > span {
    border: 1px solid #ccc;
    font-size: 12px;
    margin-right: 10px;
    box-sizing: border-box;
    display: inline-block !important;
    height: 34px !important;
    padding: 0 !important;
    width: 34px !important;
  }
  #goods-content > .goods > .goods-info > .selection > .color > span > img {
    height: 30px;
    vertical-align: middle;
    width: 30px;
  }
  #goods-content > .goods > .goods-info > .selection > .capacity > span {
    border: 1px solid #ccc;
    font-size: 12px;
    margin-right: 10px;
    padding: 10px;
  }
  #goods-content > .goods > .goods-info > .selection > .num {
    margin: 20px 0;
    align-items: center;
    display: flex;
  }
  #goods-content > .goods > .goods-info > .selection > .num > label {
    margin-left: 10px;
    margin-right: 25px;
    font-size: 12px;
    margin-bottom: 3px;
    text-align: justify;
    text-align-last: justify;
    width: 50px !important;
  }
  #goods-content > .goods > .goods-info > .selection .number {
    position: relative;
    line-height: 30px;
    width: 130px;
  }
  #goods-content > .goods > .goods-info > .selection input {
    width: 100%;
    padding-left: 39px;
    padding-right: 39px;
    height: 32px;
    line-height: 32px;
    background-color: #fff;
    background-image: none;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    box-sizing: border-box;
    color: #606266;
    text-align: center;
  }
  #goods-content > .goods > .goods-info > .buy-btn {
    display: flex;
  }
  #goods-content > .goods > .goods-info > .buy-btn > .buy {
    background: #ff531b;
    color: #fff;
    font-size: 16px;
    height: 46px;
    line-height: 46px;
    margin-left: 10px;
    text-align: center;
    width: 140px;
  }
  #goods-content > .goods > .goods-info > .buy-btn > .add-cart {
    background: #0099a8;
    color: #fff;
    font-size: 16px;
    height: 46px;
    line-height: 46px;
    margin-left: 10px;
    text-align: center;
    width: 140px;
  }
  #goods-content > .goods > .goods-info > .buy-btn > .kefu {
    background: #fff;
    border: 1px solid #0099a8;
    color: #0099a8;
    cursor: pointer;
    height: 44px;
    line-height: 46px;
    margin-left: 10px;
    text-align: center;
    width: 140px;
  }

  .introduction {
    display: flex;
    margin-top: 100px;
    width: 1200px;
  }
  .introduction > .recommend {
    width: 260px;
  }
  .introduction > .detail {
    margin-left: 20px;
    width: 920px;
  }
  .introduction > .detail > .title {
    background: #f7f7f7;
    border: 1px solid #ededed;
    border-bottom-color: #0099a8;
    display: flex;
    height: 40px;
    top: 60px;
  }
  .introduction > .detail > .title > p {
    font-size: 14px;
    font-weight: 400;
    height: 40px;
    line-height: 40px;
    text-align: center;
    width: 110px;
    text-align: center;
  }
  .introduction > .detail > .title > p:first-of-type {
    background-color: #0099a8;
    color: #fff;
  }
  .introduction > .detail > .title > p:hover {
    background-color: #0099a8;
    color: #fff;
  }
  .introduction > .detail > .content {
    margin-top: 20px;
    text-align: center;
  }
  .introduction-img {
    width: 750px;
  }
</style>